﻿function disableField(obj1, obj2){
	if (obj1.checked == true)  obj2.disabled=true;
	else obj2.disabled=false;
}

function showadv(aniFlag){
	if(document.addvacancyForm.advshow.checked == true) {
		document.getElementById('adv').style.display = "";
		document.getElementById('openAdv').style.display = 'none';
		document.getElementById('closeAdv').style.display = '';
		if(aniFlag) softScroll('advItemsCon',15,50);
	}
	else{
		document.getElementById('adv').style.display = "none";
		document.getElementById('openAdv').style.display = '';
		document.getElementById('closeAdv').style.display = 'none';
	}
}

function switchJobnum(target){
     var objText = document.addvacancyForm.jobnum;
	 var objCheckbox = document.addvacancyForm.nolimitednum;
	 if(target.type.toLowerCase()=='text'){
	 if(objText.value=='若干'){
	    objText.value=1;
		objCheckbox.checked=false;
	 }}
	 else if(target.type.toLowerCase()=='checkbox')
	 if(objCheckbox.checked) objText.value='若干';
	 else objText.value=1;
}

function fnShowConfirmSave(e){
	showPopup('info4save',e);
	showBodyMask();
}
function fnCloseConfirmSave(){
	hideBodyMask();
	hideCurrentPopup();
}
function fnSaveCancel(){
	fnCloseConfirmSave();
}
function fnSaveOk(){
	for(var i=0;window['sel'][i];i++) window['sel'][i].disabled = false;
	document.addvacancyForm.submit();
}

function applyVac(){
	var rItems = document.addvacancyForm.applyonline;
	var i;
	if(rItems&&rItems.length){
		var obj0 = [document.getElementById('filter_email'),document.getElementById('emailApply')];
		for(i=0;obj0[i];i++) obj0[i].style.display=rItems[0].checked?'':'none';
		var obj1 = [document.getElementById('applyonline2Detail')];
		for(i=0;obj1[i];i++) obj1[i].style.display=rItems[1].checked?'':'none';
	}
}

function fixNumber(v,v4null,ok0,okNeg){// int or -int
	var flagNeg = okNeg&&v.charAt(0)=='-';
	var numFixed = v.replace(/\D/g,'');
	numFixed = numFixed==''?'':numFixed*1;
	numFixed = flagNeg?'-'+numFixed:numFixed;
	if(numFixed.toString()=='-0') numFixed = '-';
	if(!ok0&&numFixed.toString()=='0') numFixed = '';
	if(v4null&&(numFixed==''||numFixed=='-')) numFixed = v4null;
	return numFixed;
}

function fnCheckJobNum(o,v4null,e){
	//o.value = fixJobNum(o.value,flag);
	var myEve = e?e:window.event;
	var k = myEve.keyCode;
	if(k!=8&&k!=46&&k!=37&&k!=39&&k!=36&&k!=35) o.value = fixNumber(o.value,v4null);
}
/*function fixJobNum(v,flag){
	var strFixed = '';
	var firstNumReg = /[1-9]/;
	var firstChar = v.charAt(0)||null;
	if(firstChar!=null){
		var nofirstNum = v.substring(1);
		if(firstNumReg.test(firstChar)) strFixed += firstChar;
		strFixed += nofirstNum.replace(/\D/g,'');
	}
	if(flag&&strFixed=='') strFixed = '若干';
	return strFixed;
}*/
function fnBlurJobNum(o,e){
	fnCheckJobNum(o,'若干',e);
	var checkbox = document.addvacancyForm.nolimitednum;
	if(o.value=='若干'&&!checkbox.checked)  checkbox.checked = true;
}

function fnCheckSeqNum(o,e){
	//o.value = fixSeqNum(o.value);
	var myEve = e?e:window.event;
	var k = myEve.keyCode;
	if(k!=8&&k!=46&&k!=37&&k!=39&&k!=36&&k!=35) o.value = fixNumber(o.value);
}
/*function fixSeqNum(v){
	var strFixed = '';
	var firstNumReg = /[1-9]/;
	var firstChar = v.charAt(0)||null;
	if(firstChar!=null){
		var nofirstNum = v.substring(1);
		if(firstNumReg.test(firstChar)) strFixed += firstChar;
		strFixed += nofirstNum.replace(/\D/g,'');
	}
	return strFixed;
}*/

var emailSeparator = ',';
var emailMax = 10;
function fnCheckRadio(){
	var r = document.addvacancyForm.applyonline;
	if(!r[1].checked){
		r[1].checked = true;
		applyVac();
	}
}
function fnShowApplyMore(){
	var html1 = document.getElementById('applyonlineItem3');
	var html2 = document.getElementById('applyonlineMore');
	html1.style.display = '';
	html2.style.display = 'none';
}
function selectEmail(s){
	var list = document.addvacancyForm.emaillist;
	var added = list.value!=''?emailSeparator+list.value+emailSeparator:list.value;
	if(s.value!='-1'&&added.indexOf(emailSeparator+s.value+emailSeparator)==-1){
		addEmail(s.value);
		s.value='-1';
	}
	else{
		if(s.value!='-1') alert(s.value+'已经添加！');
	}
}
function addEmail(e){
	var list = document.addvacancyForm.emaillist;
	var con = document.getElementById('resume2emailCon');
	var addedL = list.value==''?0:list.value.toString().split(emailSeparator).length;
	if(addedL<emailMax){
		list.value += list.value==''?e:emailSeparator+e;
		con.innerHTML += '<div class="emailItem" id="emailItem_'+e+'"><div class="emailCon">'+e+'</div><div class="deleteEmail" onclick="delEmail(\''+e+'\')" title="删除'+e+'"></div></div>';
		document.body.focus();
		hideCurrentPopup();
		if(list.value!='') con.style.display = '';
		else con.style.display = 'none';
	}
	else{
		alert('您最多可以转发到10个邮箱！');
	}
}
function delEmail(e){
	var list = document.addvacancyForm.emaillist;
	var con = document.getElementById('resume2emailCon');
	var added = (emailSeparator+list.value+emailSeparator).replace(emailSeparator+e+emailSeparator,emailSeparator);
	if(added==emailSeparator) list.value = '';
	else list.value = added.substring(1,added.length-1);
	var addedHTML = con.childNodes;
	for(var i=0;addedHTML[i];i++){
		if(addedHTML[i].id.substr('emailItem_'.length)==e){
			document.getElementById('resume2emailCon').removeChild(addedHTML[i]);
			break;
		}
	}
	if(list.value!='') con.style.display = '';
	else con.style.display = 'none';
}
function addEmailCus(e){
	var txt = document.addvacancyForm.addNewEmail;
	var mail = e.replace(/^\s*(.*)/, "$1").replace(/(.*?)\s*$/, "$1").replace(/^　*(.*)/, "$1").replace(/(.*?)　*$/, "$1");
	var patn = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$/;
	if(mail==''){
		alert('请输入Email！');
		txt.focus();
		return;
	}
	if(!patn.test(mail)){
		alert('Email格式不正确！');
		txt.focus();
		return;
	}
	var list = document.addvacancyForm.emaillist;
	var added = list.value!=''?emailSeparator+list.value+emailSeparator:list.value;
	if(added.indexOf(emailSeparator+mail+emailSeparator)>-1){
		alert(mail+'已经添加！');
		txt.focus();
		return;
	}
	else{
		addEmail(mail);
		txt.value = '';
	}
}

function trySetDefaultText(obj,txt){
	if(obj.value==""){
		obj.value = txt;
		obj.style.color = '#8c8c8c';
	}
	else obj.style.color = '#000000';
}
function tryClearDefaultText(obj,txt){
	if(obj.value==txt){
		obj.value = '';
		obj.style.color = '#000000';
	}
}

function fnCloseNocompinfo(){
	hideBodyMask();
	hideCurrentPopup();
	if (document.getElementById('nomorecompinfo').checked == true){
		var data = 't='+Date.parse(new Date());
		submitCallback(data,'/s/vacainfo/SetShowCompType.asp',SetCompType,'get');
	}
}
function SetCompType(){}
function fnShowNocompinfo(divId,e){
	showPopup(divId,e);
	showBodyMask();
}

function showBodyMask(){
	function getDocumentWH(){
		var d = {w:0,h:0};
		if(window.innerHeight&&window.scrollMaxY) d.h=window.innerHeight+window.scrollMaxY;
		else if(document.body.scrollHeight>document.body.offsetHeight) d.h=document.body.scrollHeight;
		else d.h=document.body.offsetHeight+document.body.offsetTop;
		if(window.innerWidth&&window.scrollMaxX) d.w=window.innerWidth+window.scrollMaxX;
		else if(document.body.scrollWidth>document.body.offsetWidth) d.w=document.body.scrollWidth;
		else d.w=document.body.offsetWidth+document.body.offsetLeft;
		return d;
	}
	
	if(typeof(window['bodyMask'])=='undefined'||!window['bodyMask']){
		var myDiv = document.createElement('div');
		myDiv.className = 'bodyMask';
		myDiv.style.zIndex = '999';
		myDiv.style.visibility = 'hidden';
		myDiv.style.top = '0px';
		myDiv.style.left = '0px';
		myDiv.onclick = function(e){var myEve = window.event?window.event:e;myEve.cancelBubble=true;}
		if(typeof(myDiv.style.filter)!='undefined') myDiv.style.filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
		else myDiv.style.MozOpacity = 0.7;
		document.body.appendChild(myDiv);
		window['bodyMask'] = myDiv;
	}
	if(window['bodyMask']){
		var docWH = getDocumentWH();
		window['bodyMask'].style.width=docWH.w + 'px';
		window['bodyMask'].style.height=docWH.h + 'px';
		window['bodyMask'].style.visibility='visible';
		window.flagHideCurPopup = true;//IE bodyDivMask bug
		if(window['bodyMask'].currentStyle&&navigator.userAgent.indexOf("MSIE 7")==-1){//ie6
			var allSelect = document.getElementsByTagName('select');
			window['sel'] = new Array();
			for(var i=0;allSelect[i];i++){
				if(!allSelect[i].disabled){
					window['sel'].push(allSelect[i]);
					allSelect[i].disabled = true;
				}
			}
		}
	}
}
function hideBodyMask(){
	if(window['bodyMask']) window['bodyMask'].style.visibility = 'hidden';
	window.flagHideCurPopup = false;//IE bodyDivMask bug
	var selObj;
	if(window['sel']&&window['sel'].length) while(window['sel'][0]){
		selObj = window['sel'].shift();
		selObj.disabled = false;
	}
}